<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Promise 测试</title>
  </head>
  <body>
    <script>
      // function p1 () {
      //   return new Promise(function (resolve, reject) {
      //     reject('hello');
      //   })
      // }
      // p1()
      //   .then(value => console.log(value))
      //   .catch(reason => console.log(reason))


      // function p1 (){
      //   return new Promise((resolve, reject) => {
      //     setTimeout(()=>{
      //       resolve('p1')
      //     }, 2000)
      //   })
      // }
      // function p2 (){
      //   return new Promise((resolve, reject) => {
      //       resolve('p2')
      //   })
      // }
      // Promise.all(['a', 'b', p1(), p2(), 'c']).then(res => {
      //   // result -> ['a', 'b', 'p1', 'p2', 'c']
      //   console.log(res, 'all res')
      // })


      // function p1 (){
      //   return new Promise((resolve, reject) => {
      //     setTimeout(()=>{
      //       resolve('hello')
      //     }, 2000)
      //   })
      // }
      // Promise.resolve(10).then(value => console.log(value, '10resolve value'))
      // Promise.resolve(p1()).then(value => console.log(value, 'resolve value'))


      // p1().finally(()=>{
      //   console.log('finally')
      // }).then(value=>{
      //   console.log(value, 'finally value')
      // })

      function p3 (){
        return new Promise((resolve, reject) => {
          setTimeout(()=>{
            reject('hello')
          }, 2000)
        })
      }


      p3().then(value => {
        console.log(value , 'value catch')
      }).catch(error => {
        console.log(error, 'error catch')
      })
    </script>
  </body>
</html>
